/**
 * 页面框架
 */
(function ($, owner) {
    owner.frame = function () {
        dux.init();
    };
}(jQuery, window.base = {}));


/**
 * 论坛
 */
(function ($, owner) {
    owner.editor = function ($el, config) {
        Do('editor_md', function () {
  /*          var id = $($el).attr('id');

            var toolbarOptions = [
                ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
                ['blockquote', 'code-block'],

                [{ 'header': 1 }, { 'header': 2 }],               // custom button values
                [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                [{ 'script': 'sub'}, { 'script': 'super' }],      // superscript/subscript
                [{ 'indent': '-1'}, { 'indent': '+1' }],          // outdent/indent
                [{ 'direction': 'rtl' }],                         // text direction

                [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
                [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

                [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
                [{ 'font': [] }],
                [{ 'align': [] }],

                ['clean']                                         // remove formatting button
            ];

            Quill.register('modules/markdownShortcuts', MarkdownShortcuts);

            var quill = new Quill($el, {
                modules: {
                    toolbar: toolbarOptions,
                    markdownShortcuts: {}
                },
                placeholder: 'Compose an epic...',
                theme: 'snow'
            });
            window[id ? id : 'quill'] = quill;
            var Delta = Quill.import('delta');
            var change = new Delta();
            quill.on('text-change', function(delta) {
                change = change.compose(delta);
            });
            setInterval(function() {
                if (change.length() > 0) {
                    console.log('Saving changes', change);
                    app.debug(change);
                    /!*
                    Send partial changes
                    $.post('/your-endpoint', {
                      partial: JSON.stringify(change)
                    });

                    Send entire document
                    $.post('/your-endpoint', {
                      doc: JSON.stringify(quill.getContents())
                    });
                    *!/
                    change = new Delta();
                }
            }, 5*1000);
*/


            var id = $($el).attr('id');
            window[id ? id : 'simplemde'] = new SimpleMDE({
                element: $($el)[0],
                autosave: {
                    enabled: true,
                    uniqueId: "DuxBBS",
                    delay: 1000
                },
                forceSync: true,
                styleSelectedText: false,
                spellChecker: false,
                showIcons: ["code", "table"]
            });

        });
    };
}(jQuery, window.topics = {}));